using Cysharp.Threading.Tasks;
using EventBus;
using Statistics.Count;
using UnityEngine;

namespace Statistics.Logger.TimeLogger
{
    public class SenderTimeLogger : ISender
    {
        private readonly ISender _sender;

        public SenderTimeLogger(ISender sender)
        {
            _sender = sender;
        }

        public void SendAction<T1, T2, T3, T4, T5, T6, T7, T8>(object callback, int argCount, T1 arg1, T2 arg2, T3 arg3, T4 arg4,
            T5 arg5, T6 arg6, T7 arg7, T8 arg8)
        {
            var sw = ValueStopwatch.StartNew();
            _sender.SendAction(callback, argCount, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8);
            Debug.Log($"    事件处理 耗时:{sw.GetElapsedTime().Milliseconds:F02}");
        }

        public async UniTask SendActionAsync<T1, T2, T3, T4, T5, T6, T7, T8>(object callback, int argCount, T1 arg1, T2 arg2, T3 arg3,
            T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8)
        {
            var sw = ValueStopwatch.StartNew();
            await _sender.SendActionAsync(callback, argCount, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8);
            Debug.Log($"    事件处理 耗时:{sw.GetElapsedTime().Milliseconds:F02}");
        }

        public TResult SendFunc<T1, T2, T3, T4, T5, T6, T7, T8, TResult>(object callback, int argCount, T1 arg1, T2 arg2, T3 arg3,
            T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8)
        {
            var sw = ValueStopwatch.StartNew();
            var result = _sender.SendFunc<T1, T2, T3, T4, T5, T6, T7, T8, TResult>(callback, argCount, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8);
            Debug.Log($"    事件处理 耗时:{sw.GetElapsedTime().Milliseconds:F02}");
            return result;
        }

        public async UniTask<TResult> SendFuncAsync<T1, T2, T3, T4, T5, T6, T7, T8, TResult>(object callback, int argCount, T1 arg1, T2 arg2, T3 arg3,
            T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8)
        {
            var sw = ValueStopwatch.StartNew();
            var result = await _sender.SendFuncAsync<T1, T2, T3, T4, T5, T6, T7, T8, TResult>(callback, argCount, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8);
            Debug.Log($"    事件处理 耗时:{sw.GetElapsedTime().Milliseconds:F02}");
            return result;
        }
    }
}